package com.erp.auto.controller;


import com.erp.auto.domain.ErpAutoViolationInfo;
import com.erp.auto.domain.ErpAutoViolationRecord;
import com.erp.auto.mapper.ErpAutoSellerStoreConfigMapper;
import com.erp.auto.mapper.ErpAutoViolationInfoMapper;
import com.erp.auto.service.ErpAutoSellerStoreConfigService;
import com.erp.auto.service.ErpAutoViolationInfoService;
import com.erp.auto.service.ErpAutoViolationRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;


/**
 * 自动化违规信息
 *
 * @author WXX
 * @date 2024-01-11 09:41:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/kjerp/erpAutoViolationInfo")
@Slf4j
public class ErpAutoViolationInfoController {

    @Autowired
    ErpAutoViolationInfoService erpAutoViolationInfoService;
    @Autowired
    ErpAutoViolationRecordService violationRecordService;
    /**
     * 根据店铺查询违规信息
     */
    @GetMapping("/getViolationByStoreId")
    public R<Object> getList(Long storeId, @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        ErpAutoViolationInfo info = erpAutoViolationInfoService.getViolationByStoreId(storeId);
        if (info != null) {
            // 查询记录列表
            ErpAutoViolationRecord record = new ErpAutoViolationRecord();
            record.setStoreCn(storeId.toString());
            PageHelper.startPage(pageNum, pageSize);
            List<ErpAutoViolationRecord> violationRecordList = violationRecordService.getList(record);
            PageInfo<ErpAutoViolationRecord> pageInfo  = new PageInfo<>(violationRecordList);
            info.setRecords(pageInfo);
            return R.ok(info);
        }
        info = new ErpAutoViolationInfo();
        return R.ok(info);
    }

    /**
     * 拉取店铺违规信息
     */
    @GetMapping("/pullViolationInfo")
    public void pullViolationInfo() {
        erpAutoViolationInfoService.pullViolationInfo();
    }

}
